/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package xml2postgreconvertor;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;

/**
 *
 * @author swosh
 */
public class Util {
    public static Document getXML(File fPath) {
        try {

            DocumentBuilder dbuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            //Document doc = dbuilder.parse(fPath);
            File fPathA = fPath.getAbsoluteFile();
            Document docA = dbuilder.parse(fPathA);
            return docA;
        } catch (Exception e) {
            System.err.print("Parsing of " + fPath.getPath() + " failed !!! \n" + e);
            return null;
        }
    }
    public static void copyFile(File source, File dest) throws IOException {
        FileChannel in = null, out = null;
        try {
            in = new FileInputStream(source).getChannel();
            out = new FileOutputStream(dest).getChannel();

            long size = in.size();
            MappedByteBuffer buf = in.map(FileChannel.MapMode.READ_ONLY, 0, size);

            out.write(buf);

        } finally {
            if (in != null) {
                in.close();
            }
            if (out != null) {
                out.close();
            }
        }
    }

}
